package com.it.you.controller.teacher;

import com.it.you.common.aop.LogAnno;
import com.it.you.entity.dto.TeacherDTO;
import com.it.you.entity.pojo.TbTeacher;
import com.it.you.service.teacher.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController()
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @GetMapping("/getTeacherById")
    public TbTeacher getTeacherById(@RequestParam Long id) {
        return teacherService.getById(id);
    }

    @LogAnno(operateType = "添加或更新老师信息")
    @PostMapping("/saveOrUpdate")
    public void saveOrUpdate(@RequestBody TeacherDTO dto) {
        teacherService.saveOrUpdate(dto);
    }

    //    @LogAnno(operateType = "批量添加老师信息")
    @PostMapping("/saveTeachers")
    public void saveTeachers(@RequestBody List<TeacherDTO> list) {
        teacherService.saveTeachers(list);
    }

    @PostMapping("/getBatchTeacherByIdsAsync")
    public List<TbTeacher> getBatchTeacherByIdsAsync(@RequestBody List<Long> ids) {
        try {
            return teacherService.getBatchTeacherByIdsAsync(ids);
        } catch (InterruptedException e) {
            e.printStackTrace();
            return null;
        }
    }

    @PostMapping("/getBatchTeacherByIdsSync")
    public List<TbTeacher> getBatchTeacherByIdsSync(@RequestBody List<Long> ids) {
        return teacherService.getBatchTeacherByIdsSync(ids);
    }

}
